<template>
	<view style="height: 100%; position: relative;">

		<view style="position: fixed; top: 0; width: 100%; z-index: 10; margin-top: 80rpx;">
			<view class="cu-card article">
				<view class="cu-item shadow">
					<view class=" solid-bottom padding justify-between">
						<view class="text-lg" style="width: 750rpx;">
						</view>
						<u-row style="margin-top: 20px;">
							<u-col span="2">

							</u-col>
							<u-col span="8">
								<u--input placeholder="车牌号" v-model="carPlate" suffixIconStyle="color: #909399">
								</u--input>
							</u-col>
							<u-col span="4">

							</u-col>
						</u-row>
						<u-row style="margin-top: 20px;">
							<u-col span="1">
													
							</u-col>
							
							<u-col span="4">
								<u-button type="primary" size="mini" style="width: 200rpx; height: 60rpx;  "
									@click="pageto('/pages/carInfo/carInfo')">
									新增</u-button>
							</u-col>
							<u-col span="1">
													
							</u-col>
						
							<u-col span="4">
								<u-button type="primary" size="mini" style="width: 200rpx; height: 60rpx;  "
									@click="getCarPlate">
									查询</u-button>
							</u-col>
							
							
						</u-row>
					
					</view>
				</view>
			</view>
		</view>
		<view style="margin-top: 360rpx;">
			<view class="cu-card article" v-for="item in carList"
				>
				<view class="cu-item shadow">
					<view class="flex solid-bottom padding justify-between">
						<view class="text-lg" style="width: 750rpx;">
							<u-row style="margin-top: 20px;">
								<u-col span="4" @click="pageto('/pages/carInfo/carInfo',item.plateNo)">
									车牌号:
								</u-col>
								<u-col span="6" @click="pageto('/pages/carInfo/carInfo',item.plateNo)">
									{{item.plateNo}}
								</u-col>
								<u-col span="2">

									<u-button type="primary" size="mini" style="width: 100rpx;  "
										@click="userCarDelete(item.plateNo)">
										删除</u-button>
								</u-col>

							</u-row>
							<u-row style="margin-top: 10px;" @click="pageto('/pages/carInfo/carInfo',item.plateNo)">
								<u-col span="4">
									登记时间:
								</u-col>
								<u-col span="12">
									<view v-if="item.lastTime!=null">{{item.lastTime}}</view>
									<view v-if="item.lastTime==null">{{item.createTime}}</view>
								</u-col>
							</u-row>
						</view>

					</view>
				</view>
			</view>
			<view v-if="total!=0">
				<pagination :total="total" :page-size="data.pageSize" :current-page="pageNo"
					@page-change="handlePageChange" />

			</view>

		</view>

	</view>
</template>

<script>
	import Pagination from '@/components/Pagination.vue'

	import {
		getAction,
		delAction
	} from '@/api/api.js';
	export default {
		components: {
			Pagination,
		},
		data() {
			return {
				data: {
					pageSize: 10,
					column: 'createTime',
					order: 'desc',
					driverName: '',
					plateNo: '',
				},
				getCarListUrl: '/carPersonnel/carPersonnel/m/list',
				total: 0,
				carList: [],
				pageNo: 1,
				carPlate: '',
				wxOpenId: '',
			
			}
		},
		onLoad() {
			if (uni.getStorageSync("openId")) {
				this.wxOpenId = uni.getStorageSync("openId")
			} else {
				this.wxOpenId = 'oFTXH5jAW_5SyyvcXGPTkuosS4bw'
			}
			this.getCarList()
			
		},
		methods: {
			getCarList() {
				this.plateList = []

				this.data.pageNo = this.pageNo
				if (this.data.pageNo == 0) {
					this.data.pageNo == 1
				}
				getAction(this.getCarListUrl, this.data).then(res => {

					this.carList = res.result.records
					this.total = res.result.total

				})
			},
			handlePageChange(page) {
				this.pageNo = page;
				this.getCarList()
			},
			userCarDelete(plate) {

				let url = '/carPersonnel/carPersonnel/m/delete?openId=' + this.wxOpenId + "&plateNo=" + plate
				delAction(url).then(res => {
					if (res.success) {
						this.pageNo = 1
						this.getCarList()
					}
				})


			},
			getCarPlate() {

				this.pageNo = 1
				this.data.plateNo = "*" + this.carPlate + "*"
				this.getCarList()




			},
			pageto(url, plateNo) {
				let urls=url;
				console.log(url);
				if(plateNo){
					urls=url+ "?plateNo=" + plateNo
				}
				console.log(urls);
				uni.navigateTo({
					url: urls
				})
			},
			
		}
	}
</script>

<style>
</style>
